<?php
echo '<form action="index.php" method="POST"><input type=submit value=Anuluj name="lacz_pac_anuluj" class="butt4"></form><br>';

if ($_POST['lacz_pac_zatwierdz']){
    $sql="select * from wizyty where id_pac=".$_SESSION['pac_zr'][0];
    $result=mysql_query($sql);
while($row = mysql_fetch_array($result))
{
$wiz_do_przepisania[]=$row['id'];
}
    $wiz_przep_arch=implode(';', $wiz_do_przepisania);
    $sql2="insert into pac_polaczeni values (".$_SESSION['pac_zr'][0].", ".$_SESSION['pac_doc'][0].", '".$wiz_przep_arch."')";
    mysql_query($sql2);
    logg($sql2, $_SESSION['u']);
    $sql3="update pac set akt=0 where id=".$_SESSION[pac_zr][0];
    mysql_query($sql3);
    logg($sql3, $_SESSION['u']);
    $sql4="update wizyty set id_pac=".$_SESSION['pac_doc'][0]." where id_pac=".$_SESSION['pac_zr'][0];
    mysql_query($sql4);
    logg($sql4, $_SESSION['u']);
    unset ($_SESSION['pac_zr'], $_SESSION['pac_doc']);
    echo '<font color=green><b>Pomyślnie połączono pacjentów</b></font><br>';
}

if ($_POST['lacz_pac_zamien']){
$temp=$_SESSION['pac_doc'];
$_SESSION['pac_doc']=$_SESSION['pac_zr'];
$_SESSION['pac_zr']=$temp;
}

if (($_SESSION['pac_doc'][0] == $_SESSION['pac_zr'][0]) && ($_SESSION['pac_doc'][0]<>'' && $_SESSION['pac_zr'][0]<>'')) {
echo 'Wybrano tego samego pacjenta !!!<br>';
unset ($_SESSION['pac_doc'], $_SESSION['pac_zr']);
}

if ($_POST['wyb_pac_lacz']){
$_SESSION['pac_zr']=array_keys($_POST['wyb_pac_lacz']);
}
if ($_POST['wyb_pac_lacz2']){
$_SESSION['pac_doc']=array_keys($_POST['wyb_pac_lacz2']);
}
if ($_SESSION['pac_zr']=='') {
echo 'Pacjent źródłowy';
include "pacjenci.php";
}
if ($_SESSION['pac_doc']=='' && $_SESSION['pac_zr']<>'') {
echo 'Pacjent docelowy';
include "pacjenci.php";
}
if ($_SESSION['pac_doc']<>'' && $_SESSION['pac_zr']<>'') {
echo '<table><tr><td>Pacjent źródłowy:</td><td>&nbsp;</td><td>Pacjent docelowy</td></tr><tr><td>';
$_SESSION['lacz_pac_ktory']=0;
include ('pac_ed.php');
echo '</td><td align="center">';
echo '<form action="index.php" method="POST"><input type=submit value=">> Zamień <<" name="lacz_pac_zamien" class="butt4"></form><br><br><form action="index.php" method="POST"><input type=submit value=">> Połącz >>" name="lacz_pac_zatwierdz" class="butt"></form></td><td>';
$_SESSION['lacz_pac_ktory']=1;
include ('pac_ed.php');
unset ($_SESSION['lacz_pac_ktory']);
echo '</td></tr></table>';
}



?>